package com.xxxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxy.dao.FacultyDao;
import com.xxxy.model.Faculty;
import com.xxxy.service.FacultyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sjh
 * @date 2022/2/1 12:27
 */
@Service
public class FacultyServiceImpl extends ServiceImpl<FacultyDao, Faculty> implements FacultyService {

    @Autowired
    FacultyDao facultyDao;

    @Override
    public List<Faculty> list(){
        return  facultyDao.selectList(null);
    }

    @Override
    public Map<Integer,String> getItemMap(){
        Map<Integer,String> map = new HashMap<>();
        List<Faculty> list = facultyDao.selectList(null);
        for (int i=0; i<list.size(); i++){
            Faculty faculty = list.get(i);
            map.put(faculty.getId(),faculty.getFacultyName());
        }
        return map;
    }

    @Override
    public Faculty getByName(String facultyName) {
        LambdaQueryWrapper<Faculty> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Faculty::getFacultyName, facultyName);
        Faculty faculty = facultyDao.selectOne(lambdaQueryWrapper);
        return faculty;
    }
}
